<template>
	<div class="login">
		<el-row>
			<el-col :span="8">
				<div class="left">
					<ul>
						<li><img class="logo" src="../../static/img/login-icon.jpg"></li>
						<li><input class="ipt" type="text" v-model="username" placeholder="请输入用户名"></li>
						<li><input class="ipt" type="password" v-model="password" placeholder="请输入密码"></li>
						<li>
							<input class="ipt" type="text" v-model="validCode" placeholder="请输入验证码" @keyup.13="login">
							<img :src="validCodeImg" alt="..." class="valicode-img" style="cursor: pointer;" @click="updateCodeImg">
						</li>
					</ul>
					<img class="login-btn" src="../../static/img/login-btn.jpg" @click="login">
				</div>
			</el-col>
			<el-col :span="16">
				<div class="right">
					<img class="right-bg" src="../../static/img/right-bg.jpg">
					<img class="right-title" src="../../static/img/right-img1.png">
					<img class="right-logo" src="../../static/img/right-img2.png">
					<div class="foot">豪德天沐科技有限公司 荣誉出品</div>
				</div>
			</el-col>
		</el-row>
	</div>
</template>

<script>
export default {
  name: "login",
  mounted: function() {
    $(".left").height($(window).height() - 60);
    $(".right-bg").height($(window).height());
    $(".right").height($(window).height());
    this.updateCodeImg();
  },
  data() {
    return {
      username: "",
      password: "",
      validCode: "",
      validCodeImg: process.env.API_BASH_URL + "validateCode"
    };
  },
  methods: {
    updateCodeImg() {
      this.validCodeImg =
        process.env.API_BASH_URL + "validateCode?t=" + Math.random();
    },
    login() {
      let that = this;
      that.$http.post(
        "loginIn",
        {
          username: that.username,
          password: that.password,
          validCode: that.validCode
        },
        d => {
          if (d.status == "1") {
            //获取登陆用户
            that.$http.get("main/index/user", d => {
			if(d.resultCode == 0) {
				session.set(process.env.SESSION_KEY_USER, d.record);
				that.$router.push("/index");
              }
            });
          } else {
            layer.msg(d.msg, { shift: 6 });
            that.updateCodeImg();
          }
        }
      );
    }
  }
};
</script>

<style scoped>
.valicode-img {
  position: absolute;
  right: 30%;
}
.logo {
  margin-bottom: 30px;
}

.left {
  width: 84%;
  padding: 30px 8%;
  float: left;
  background: #fff;
  position: relative;
}

.left ul li {
  width: 100%;
  float: left;
  margin-bottom: 30px;
  position: relative;
}

.ipt {
  width: 70%;
  float: left;
  border-bottom: 1px solid #dbdbdb;
  padding: 15px 0;
  font-size: 16px;
}

.login-btn {
  width: 300px;
  position: absolute;
  bottom: 80px;
  left: 8%;
  cursor: pointer;
}

.right {
  width: 100%;
  position: relative;
  float: left;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
}

.right-bg {
  float: left;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.right-title {
  width: 690px;
  position: relative;
}

.right-logo {
  position: relative;
}

.foot {
  position: relative;
  color: #fff;
}

@media screen and (max-width: 1400px) {
  .right-title {
    width: 490px;
    position: relative;
  }
  .right-logo {
    width: 200px;
    position: relative;
  }
}
</style>